const router = require('koa-router')();
router.prefix(appConfig.authPrefixUrl+'/desktop/sys_auth_type');
const SysAuthTypeService = appRequire('service/desktop/SysAuthTypeService.js');
const ResultVo = require(appConfig.rootUrl+'/vo/ResultVo.js');

router.post('/save',async(ctx)=>{
  try{
    let authType = ctx.request.body;
    let id = await SysAuthTypeService.save(authType);
    ctx.body = ResultVo.success('success',id);
  }catch(err){
    //集中处理错误
    err.msg = "新增系统类型失败!";
    ctx.app.emit('error', err, ctx);
  }
});
router.get('/deleteOne',async(ctx)=>{
  try{
    let authType = ctx.query;
    authType = await SysAuthTypeService.deleteOne(authType.id);
    ctx.body = ResultVo.success('success',authType);
  }catch(err){
    //集中处理错误
    err.msg = "删除系统类型失败!";
    ctx.app.emit('error', err, ctx);
  }
});
router.post('/deleteMany',async(ctx)=>{
  try{
    let param = ctx.request.body;
    console.log(param);
    param = await SysAuthTypeService.deleteMany(param.ids);
    ctx.body = ResultVo.success('success',param);
  }catch(err){
    //集中处理错误
    err.msg = "删除系统类型失败!";
    ctx.app.emit('error', err, ctx);
  }
});
router.get('/findOne',async(ctx)=>{
  try{
    let authType = ctx.query;
    authType = await SysAuthTypeService.findOne(authType.id);
    console.log(authType);
    ctx.body = ResultVo.success('success',authType);
  }catch(err){
    //集中处理错误
    err.msg = "查找系统类型失败!";
    ctx.app.emit('error', err, ctx);
  }
});
router.get('/findAllByType',async(ctx)=>{
  try{
    let authType = ctx.query;
    let data = await SysAuthTypeService.findAllByType(authType);
    ctx.body = ResultVo.success('success',data);
  }catch(error){
    ctx.body = ResultVo.error(-1,'获取全部系统类型数据失败!');
  }
});
router.get('/findAll',async(ctx)=>{
  try{
    let data = await SysAuthTypeService.findAll();
    ctx.body = ResultVo.success('success',data);
  }catch(error){
    ctx.body = ResultVo.error(-1,'获取全部系统类型数据失败!');
  }
});
router.get('/findByPage',async(ctx)=>{
  try{
    let page = ctx.query;
    console.log(page);
    let data = await SysAuthTypeService.findByPage(page);
    ctx.body = data;
  }catch(error){
    ctx.body = ResultVo.error(-1,'获取分页系统类型数据失败!');
  }
});
module.exports = router;